<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //indexOf(x,y)获取x第一次出现位置的索引，y控制查找的起始位置索引
        //lastIndexOf(x)最后一次出现位置的索引
        //没有这个字符返回-1
        let str = "shidazhishidazhi"
        console.log(str.indexOf('z'));
        console.log(str.lastIndexOf('z'));
        console.log(str.indexOf('%'));//-1

        console.log(str.indexOf('z', 6));//13

    </script>
</body>

</html>